module.exports = options =>{
    const assert = require('http-assert') /* npm i assert */
    const Adminuser = require('../modules/Adminuser')
    const jwt = require('jsonwebtoken') /* npm i jsonwebtoken */
    return async (req,res,next)=>{
        const token = String(req.headers.authorization || '').split(' ').pop()
        assert(token,401,'请先登录')
        const {id} = jwt.verify(token,req.app.get('secret'))
        assert(id,401,'请先登录')
        req.user = await Adminuser.findById(id)
        assert(req.user,401,'请先登录')
        await next()
    }
}